/* PRE-ANALYSES DO FILE for "Exposure to Confederate Monuments: The Political
 Effect of Non-Intervention" */

clear all

*Set working directory* 
cd "H:\Personal\Datos\Confederate paper\Replication\Data\"

/* Prior to importing the data I remove variables to ensure anonymity*/


* IMPORT DATA
import excel "dataset.xlsx", sheet("Sheet0") firstrow clear


* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ············································································ *
                             * PREPARE VARIABLES *                          
* ············································································ *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *

* ··························  PRE-T SOCIODEMO  ······························· *
*1537 observations*


fre Age 
rename Age age
tab age, gen (age_)

encode Whatisyourgender, gen (gender)
fre gender
drop if gender == 3
* Individuals who identify as non-binary are removed to match block-randomization. 4 observations. 
* 1533 observations
gen woman = 0
replace woman = 1 if gender == 1


fre Whatisyourracialethnicgroup
encode Whatisyourracialethnicgroup, gen (race)
fre race
* Individuals who do not identify as Black or White are removed to match block-randomization.  9 cases.
* 1524 observations
drop if race == 1 
drop if race == 3
fre race


* Generate dummy for people who identify as Black and as White
generate black = 0
replace black = 1 if race == 2
generate white = 0
replace white = 1 if race == 4 


* Generate variables for STATE OF BIRTH
fre WhatUSstatewereyoubornin
encode WhatUSstatewereyoubornin, gen (state_born)
fre state_born, all
* 110 missing. Cannot be recoded it to an overall mean. I repeat the analysis without dropping this cases.
drop if state_born == .


* Born in the "Deep South": Georgia, Alabama, South Carolina, Mississippi, and Louisiana.
gen deep_south_states = 0
replace deep_south_states = 1 if  deep_south_states== 1 | deep_south_states== 10 | ///
deep_south_states== 17 | deep_south_states== 23 | deep_south_states== 38 

* Born in a former Confederate State*
gen confe_states_born = 0
replace confe_states_born =1 if  state_born == 1 | state_born == 4 |  state_born ==9 | ///
state_born ==10 | state_born ==17 | ///
state_born ==23 |state_born == 32 |state_born == 38 | ///
state_born == 40 |state_born == 41 |state_born == 44 

* Born in former Border States*
gen border_states_born = 0
replace border_states_born = 1 if state_born== 8 | state_born==16 | state_born==19 | ///
state_born==47 |state_born==24

* Born admin South*
gen southborn=0
replace southborn=1 if  state_born== 1 | state_born== 4 | state_born== 8 | state_born== 9 | ///
state_born== 10 |state_born== 16 | state_born== 17 | state_born== 19 | ///
state_born== 23 |state_born== 32 |state_born== 34 |state_born== 38 | ///
state_born== 40 |state_born== 41 |state_born== 44 |state_born== 47
replace southborn = . if state_born == .

gen nosouthborn = 0
replace nosouthborn = 1 if southborn == 0



* Generate variables for STATE THEY IDENTIFY WITH (BELONG)
encode WhatUSstatedoyouconsider, gen (state_belong)
fre state_belong, all 


* Belong in the "Deep South": Georgia, Alabama, South Carolina, Mississippi, and Louisiana.
gen deepbelong = 0
replace deepbelong = 1 if  state_belong== 1 | state_belong== 10 | ///
state_belong== 17 | state_belong== 23 | state_belong== 38 

gen confe_states = 0
replace confe_states=1 if  WhatUSstatedoyouconsider=="Alabama" | WhatUSstatedoyouconsider=="Arkansas" |  WhatUSstatedoyouconsider=="Florida" | ///
WhatUSstatedoyouconsider=="Georgia" | WhatUSstatedoyouconsider=="Louisiana" | ///
WhatUSstatedoyouconsider=="Mississippi" |WhatUSstatedoyouconsider=="North Carolina" |WhatUSstatedoyouconsider=="South Carolina" | ///
WhatUSstatedoyouconsider=="Tennessee" |WhatUSstatedoyouconsider=="Texas" |WhatUSstatedoyouconsider=="Virginia" 

gen border_states = 0
replace border_states = 1 if WhatUSstatedoyouconsider=="Delaware" | WhatUSstatedoyouconsider=="Kentucky" | WhatUSstatedoyouconsider=="Maryland" | ///
WhatUSstatedoyouconsider=="West Virginia" |WhatUSstatedoyouconsider=="Missouri"

gen southbelong = 0
replace southbelong=1 if  state_belong== 1 | state_belong== 4 | state_belong== 8 | state_belong== 9 | ///
state_belong== 10 |state_belong== 16 | state_belong== 17 | state_belong== 19 | ///
state_belong== 23 |state_belong== 32 |state_belong== 34 |state_belong== 38 | ///
state_belong== 40 |state_belong== 41 |state_belong== 44 |state_belong== 47
replace southbelong = . if state_belong == .

gen nosouthbelong = 0
replace nosouthbelong = 1 if southbelong == 0
ta nosouthbelong southbelong

ta southborn southbelong
*****




****
* Create variable with the right order *
fre Wehearalotoftalkthesedays
encode Wehearalotoftalkthesedays, gen(ideology) 
gen libcon = .
replace libcon = 1 if ideology == 3
replace libcon = 2 if ideology == 4
replace libcon = 3 if ideology == 7
replace libcon = 4 if ideology == 5
replace libcon = 5 if ideology == 6 
replace libcon = 6 if ideology == 1
replace libcon = 7 if ideology == 2 
drop ideology
fre libcon
tab libcon, gen (libcon_)


* Party ID
encode Generallyspeakingdoyouusual, gen (party_id)
encode Doyouthinkofyourselfasclos, gen(close_ind) 
encode M, gen(close_other) 

fre party_id
fre close_ind
fre close_other


* Create a dummy for those that identify as Democrats, including those that are closer to democrats.
gen democratlean = 0
replace democratlean = 1 if party_id == 1 | close_ind == 1 | close_other == 1
fre democratlean

* Create a dummy for those that identify as Republicans
gen republicanlean = 0
replace republicanlean = 1 if party_id == 4 | close_ind == 2 | close_other == 2
fre republicanlean

/* Drop those that are not Republicans or Democrats or lean to either. Cannot be recoded it to an overall mean.
 8 observations. I repeat the analysis without dropping those cases */
drop if democratlean == 0 & republicanlean ==0





* POLITICAL INTEREST *
encode Howinterestedwouldyousayyou, gen (polint)
fre polint
tab polint, gen (polint_)

* EDUCATION*
encode Whatisyourlevelofeducation, gen (leveledu)
fre leveledu
gen edu = . 
replace edu = 1 if leveledu == 5
replace edu = 2 if leveledu == 4
replace edu = 3 if leveledu == 8
replace edu = 4 if leveledu == 1
replace edu = 5 if leveledu == 2
replace edu = 6 if leveledu == 6
replace edu = 7 if leveledu == 3
replace edu = 8 if leveledu == 7
drop leveledu

tab edu, gen (edu_)

* INCOME *
encode Inwhichofthesegroupsdidyou, gen (levelincome)
fre levelincome
gen income = .
replace income = 1 if levelincome == 7
replace income = 2 if levelincome == 2
replace income = 3 if levelincome == 4
replace income = 4 if levelincome == 5
replace income = 5 if levelincome == 6
replace income = 6 if levelincome == 1
replace income = 7 if levelincome == 3
replace income = 8 if levelincome == 8
drop levelincome

* there are two missing. As per the PAP, I recode it to the roverall mean.
mean income
replace income = 4 if income == .
tab income, gen (income_)



* ··················· TREATMENT, CONTROL & CHECKS ····························· *

* Create dummy for those who fail/don't answer the attention check
fre Sometimesitmaybedifficultto 
gen failacheck = 0
replace failacheck = 1 if Sometimesitmaybedifficultto != "Subway"
ta failacheck Sometimesitmaybedifficultto
ta failacheck



* Rename treatment variables and generate treatment variable
rename TimingFirstClick treatfirstclick
rename TimingLastClick treatlastclick
rename TimingPageSubmit treatpagesubmit
rename TimingClickCount treatclickcount

fre treatfirstclick

gen treatment = .
destring treatfirstclick, replace
replace treatment = 1 if treatfirstclick != .
replace treatment = 0 if treatfirstclick == .
ta treatment

* Rename control variables
rename U controlfirstclick
rename V controllastclick
rename W controlpagesubmit
rename X controlclickcount


* Create variable if they know the name of the town in the video *
gen nametown = strpos(AX, "Bishopville") > 0 
fre nametown
* Create variable if they know the name of the town or name the county*
gen nametowncounty = strpos(AX, "Bishopville") > 0 | ///
 strpos(AX, "bishopville") > 0 |  ///
 strpos(AX, "lee county") > 0 |  ///
 strpos(AX, "Lee County") > 0
fre nametowncounty


* Perception of percentage of Black people in town
rename Pleasethinkaboutthepopulatio percent_black_town
fre percent_black_town

* Check if they are more likely to fail the attention check depending on 
* treatment status.
fre failacheck
regr failacheck treatment, r



* ··························  OUTCOME VARIABLES ······························ *

* Emotion variables
encode Weareinterestedinthevarious, gen(anger) 
encode AA, gen (joy)
encode AB, gen (fear)
encode AC, gen (pride)
encode AD, gen (sadness)
encode AE, gen (disgust)
encode AF, gen (hostility)

* Rearrange emotion variables to the right oder*

local emotions anger joy fear pride sadness disgust hostility

foreach var in `emotions' {
gen `var'2 = .
replace `var'2 = 1 if `var' == 4
replace `var'2 = 2 if `var' == 1
replace `var'2 = 3 if `var' == 3
replace `var'2 = 4 if `var' == 5
replace `var'2 = 5 if `var' == 2 

drop `var' 
rename `var'2 `var'
}


* GOOD PLACE TO LIVE*
destring Fromtheimagesyoujustsawdo, gen (good_place_to_live)
fre good_place_to_live


* Rename and rearrange variables to the right order*
encode Basedonwhatyousawonthevid, gen(careparks)
gen care_parks = .
replace care_parks = 1 if careparks == 4
replace care_parks = 2 if careparks == 3
replace care_parks = 3 if careparks == 5
replace care_parks = 4 if careparks == 2
replace care_parks = 5 if careparks == 1
ta careparks care_parks
drop careparks

encode AI, gen(careparking)
gen care_parking = .
replace care_parking = 1 if careparking == 4
replace care_parking = 2 if careparking == 3
replace care_parking = 3 if careparking == 5
replace care_parking = 4 if careparking == 2
replace care_parking = 5 if careparking == 1
ta careparking care_parking
drop careparking

encode AJ, gen(careracialequality)
gen care_equality = .
replace care_equality = 1 if careracialequality == 4
replace care_equality = 2 if careracialequality == 3
replace care_equality = 3 if careracialequality == 5
replace care_equality = 4 if careracialequality == 2
replace care_equality = 5 if careracialequality == 1
ta careracialequality care_equality
drop careracialequality

encode AK, gen(carefightingcrime)
gen care_fight_crime = .
replace care_fight_crime = 1 if carefightingcrime == 4
replace care_fight_crime = 2 if carefightingcrime == 3
replace care_fight_crime = 3 if carefightingcrime == 5
replace care_fight_crime = 4 if carefightingcrime == 2
replace care_fight_crime = 5 if carefightingcrime == 1
ta carefightingcrime care_fight_crime
drop carefightingcrime

encode Nowtrytothinkaboutthehisto, gen(conflicthistory)
gen conflict_history = .
replace conflict_history = 1 if conflicthistory == 5
replace conflict_history = 2 if conflicthistory == 1
replace conflict_history = 3 if conflicthistory == 2
replace conflict_history = 4 if conflicthistory == 4
replace conflict_history = 5 if conflicthistory == 3
ta conflicthistory conflict_history
drop conflicthistory

destring Ifyouhadtomakeaguessabout, gen (trust_town)
fre trust_town

rename About55inevery100Americans blm_town
fre blm_town


encode Andhowdoyoupersonallyfeela, gen(blm_personally)
fre blm_personally
gen blm_personal = .
replace blm_personal = 1 if blm_personally == 4
replace blm_personal = 2 if blm_personally == 2
replace blm_personal = 3 if blm_personally == 1
replace blm_personal = 4 if blm_personally == 3
replace blm_personal = 5 if blm_personally == 5
fre blm_personal
drop blm_personally

encode Stillthinkingaboutthecityin, gen(externalefficacy)
fre externalefficacy
gen external_efficacy = .
replace external_efficacy = 1 if externalefficacy == 1
replace external_efficacy = 2 if externalefficacy == 4
replace external_efficacy = 3 if externalefficacy == 3
replace external_efficacy = 4 if externalefficacy == 2
replace external_efficacy = 5 if externalefficacy == 5
ta external_efficacy externalefficacy
drop externalefficacy

fre Doyouthinkthatmostpeoplein
gen town_republican = 2
replace town_republican = 3 if Doyouthinkthatmostpeoplein == "Most vote for the Republican Party"
replace town_republican = 1 if Doyouthinkthatmostpeoplein == "Most vote for the Democratic Party"
replace town_republican = . if Doyouthinkthatmostpeoplein == "Other"
fre town_republican

destring Nowtrytoimaginethatyoulive, gen (valued_community)
fre valued_community

encode Judgingfromwhatyousawonthe, gen(townsupportwithdrawingus)
fre townsupportwithdrawingus
gen  town_support_withdrawing_us = .
replace town_support_withdrawing_us = 1 if townsupportwithdrawingus == 4
replace town_support_withdrawing_us = 2 if townsupportwithdrawingus == 2
replace town_support_withdrawing_us = 3 if townsupportwithdrawingus == 1
replace town_support_withdrawing_us = 4 if townsupportwithdrawingus == 3
replace town_support_withdrawing_us = 5 if townsupportwithdrawingus == 5
drop townsupportwithdrawingus

encode Andstillthinkingaboutthepe, gen (townproudsouth)
fre townproudsouth
gen town_proud_south = .
replace town_proud_south = 1 if townproudsouth == 3
replace town_proud_south = 2 if townproudsouth == 4
replace town_proud_south = 3 if townproudsouth == 2
replace town_proud_south = 4 if townproudsouth == 5
replace town_proud_south = 5 if townproudsouth == 1
drop townproudsouth


* Create varaiable for total donation *
encode Weareraffling100amongallt, gen(raffle) 
fre raffle
* partial donors*
fre AV
gen schooldonation = AV
replace schooldonation = "10" if AV == "$10"
replace schooldonation = "20" if AV == "$20"
replace schooldonation = "25" if AV == "$25.00"
replace schooldonation = "30" if AV == "$30"
replace schooldonation = "40" if AV == "$40"
replace schooldonation = "5" if AV == "$5"
replace schooldonation = "50" if AV == "$50"
replace schooldonation = "70" if AV == "$70"
replace schooldonation = "75" if AV == "$75"
replace schooldonation = "25" if AV == "25.00"
replace schooldonation = "50" if AV == "50.00"
replace schooldonation = "50" if AV == "50/50"
replace schooldonation = "0" if AV == "not school, but donate to black lives matter" 
replace schooldonation = "0" if raffle == 3 & AV == ""  
fre schooldonation


destring schooldonation, gen(donation)
replace donation = 100 if raffle == 2
replace donation = 0 if raffle == 4
fre donation

gen donationyn = 0
replace donationyn = 1 if donation!= . & donation!= 0
replace donationyn = . if donation== . 
fre donationyn

save dataset.dta, replace





* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ············································································ *
                           * T&C PRE-T BALANCE *                          
* ············································································ *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *


*First time running test* 
clear
gen variable = . 
save covariate_test.dta, replace

* Additional times running test *
use covariate_test.dta, clear
drop _all
gen variable = . 
save covariate_test.dta, replace

use dataset.dta, clear

local covar  woman black democratlean southborn southbelong age_1 age_2 age_3 age_4 age_5 age_6   ///
libcon_1 libcon_2 libcon_3 libcon_4 libcon_5 libcon_6 libcon_7 polint_1 polint_2 /// 
polint_3 polint_4  income_1 income_2 income_3 income_4 income_5 income_6 income_7 ///
income_8 edu_1 edu_2 edu_3 edu_4 edu_5 edu_6 edu_7 edu_8  confe_states_born border_states_born deep_south_states
foreach covar in `covar'{
	regr `covar' treatment, r
	regsave treatment using "covariate_test.dta", ci pval tstat level(95) append addlabel (Covariate, `covar')
}

use covariate_test.dta, clear
drop variable
save covariate_test.dta, replace
use dataset.dta, clear

